package com.fauks.gmall.managerweb.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.fauks.gmall.bean.PmsProductImage;
import com.fauks.gmall.bean.PmsProductInfo;
import com.fauks.gmall.bean.PmsProductSaleAttr;
import com.fauks.gmall.managerweb.utils.PmsUploadUtil;
import com.fauks.gmall.service.ProductService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@CrossOrigin
public class ProductController {

    @Reference
    private ProductService productService;

    @GetMapping("spuList")
    public List<PmsProductInfo> spuList(String catalog3Id) {
        return productService.getSpuList(catalog3Id);
    }

    @PostMapping("saveSpuInfo")
    public String saveSpuInfo(@RequestBody PmsProductInfo productInfo) {
        productService.saveProductInfo(productInfo);
        return "success";
    }

    @PostMapping("fileUpload")
    public String fileUpload(@RequestParam("file") MultipartFile file) {
        String imageUrl = PmsUploadUtil.uploadFile(file);
        return imageUrl;
    }

    //获取平台销售属性
    @GetMapping("spuSaleAttrList")
    public List<PmsProductSaleAttr> spuSaleAttrList(String spuId) {
        return productService.spuSaleAttrList(spuId);
    }

    @GetMapping("spuImageList")
    public List<PmsProductImage> spuImageList(String spuId) {
        return productService.spuImageList(spuId);
    }
}
